package com.springboot.test.web.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.test.common.enums.StaticKey;
import com.springboot.test.common.response.Response;
import com.springboot.test.service.GoodsService;
import com.springboot.test.service.param.AddGoodsParam;
import com.springboot.test.service.param.GoodsPageParam;
import com.springboot.test.service.param.UpdateGoodsParam;
import com.springboot.test.service.param.pageparam.BasePageParam;
import com.springboot.test.service.result.GoodsPageResult;
import com.springboot.test.service.result.MyGoodsResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("app/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @PostMapping("page")
    public Response<Page<GoodsPageResult>> goodsPage(@RequestBody GoodsPageParam param){
        return Response.success(goodsService.goodsPage(param,0));
    }

    @PostMapping("add")
    public Response<Boolean> addGoods(@RequestBody AddGoodsParam param,@RequestAttribute(StaticKey.USER_CODE)String userCode){
        return Response.success(goodsService.addGoods(param,userCode));
    }

    @PostMapping("myGoods")
    public Response<Page<MyGoodsResult>> myGoodsPage(@RequestBody BasePageParam basePageParam, @RequestAttribute(StaticKey.USER_CODE)String userCode){
        return Response.success(goodsService.myGoodsResultPage(basePageParam,userCode));
    }

    @GetMapping("update_status")
    public Response<Boolean> updateStatus(String goodsCode,Integer status){
        return Response.success(goodsService.updateStatus(goodsCode,status));
    }

    @PostMapping("update")
    public Response<Boolean> updateGoods(@RequestBody UpdateGoodsParam param){
        return Response.success(goodsService.updateGoods(param));
    }


}
